package com.example;

import com.example.quartz.job.CustomJob;
import lombok.SneakyThrows;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.spi.MutableTrigger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


public class App {

    @SneakyThrows
    public static void main(String[] args) {
        JobDetail jobDetail = JobBuilder.newJob(CustomJob.class)
                .withIdentity("job1", "job-group1")
                .usingJobData("JOB_KEY", "自定义JOB信息")
                .usingJobData("time", 0)
                .build();

        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger-group1")
                .withSchedule(simpleScheduleBuilder)
                .usingJobData("TRIGGER_KEY","自定义Trigger信息")
                .build();

        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();


    }
}
